﻿<%@ Page ContentType="application/xml" Language="C#" %> 
<script runat=server>
    /// <summary>
    /// 
    /// </summary>
    /// <param name="tablename"></param>
    /// <param name="columnname"></param>
    /// <param name="aliasname"></param>
    /// <param name="value"></param>
    /// <param name="xmlDoc"></param>
    /// <param name="parentEle"></param>
    /// <param name="editable">在手持机端是否可以手工更改</param>
    /// <returns></returns>
    private System.Xml.XmlElement AppendAttElement(string tablename, string columnname, string aliasname, string value,System.Xml.XmlDocument xmlDoc,System.Xml.XmlElement parentEle,bool editable,bool isdigital)
    {
        System.Xml.XmlElement ele = xmlDoc.CreateElement("属性");
        ele.SetAttribute("tablename", tablename);
        ele.SetAttribute("columnname", columnname);
        ele.SetAttribute("aliasname", aliasname);
        ele.SetAttribute("value", value);
        ele.SetAttribute("editable", editable.ToString());
        ele.SetAttribute("isdigital", isdigital.ToString());
        parentEle.AppendChild(ele);
        return ele;
    }
</script>
<%
    string lineids = Request.Params["lineids"];
    if (lineids != "" && lineids != null)
    {
        if (lineids.Trim() == "")
            lineids = "1.001 2.001 3.002";
        lineids = lineids.Replace(' ', ',');
        lineids = lineids.Trim(',');
    }
    string sql = "select   wireid, LINENAME,   OVERLINEID, starttower,  finishtower,   finishTOWERNAME,   installtype,   NODEDIST,   LATITUDE,   LONGITUDE,   ELEVATION,   HCHEIGHT,NODETYPE,DEVICEID,   DEVICENAME,   DEVICETYPE,   DEVICENUM from v_total where overlineid in (" + lineids + ") order by overlineid,finishtower";
    System.Data.OracleClient.OracleDataReader o = Maticsoft.DBUtility.DbHelperOra.ExecuteReader(sql);   
    System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
    xmlDoc.LoadXml("<数据列表></数据列表>");
    System.Xml.XmlElement linelistNode = xmlDoc.CreateElement("线路列表");
    System.Xml.XmlElement towerlistNode = xmlDoc.CreateElement("杆塔列表");
    xmlDoc.DocumentElement.AppendChild(linelistNode);
    xmlDoc.DocumentElement.AppendChild(towerlistNode);   
    while(o.Read())
    {
        
        string wireid =  o.GetValue(o.GetOrdinal("wireid")).ToString();
        string starttower = o.GetValue(o.GetOrdinal("starttower")).ToString(); 
        string finishtower = o.GetValue(o.GetOrdinal("finishtower")).ToString();
        string finishtowername = o.GetValue(o.GetOrdinal("finishTOWERNAME")).ToString();
        string linename = o.GetValue(o.GetOrdinal("linename")).ToString();
        string longitude = o.GetValue(o.GetOrdinal("longitude")).ToString();
        string latitude = o.GetValue(o.GetOrdinal("latitude")).ToString();
        string elevation = o.GetValue(o.GetOrdinal("elevation")).ToString();
        string installtype = o.GetValue(o.GetOrdinal("installtype")).ToString();
        string nodedist = o.GetValue(o.GetOrdinal("nodedist")).ToString();
        
        string overlineid = o.GetValue(o.GetOrdinal("overlineid")).ToString();
        string deviceid = o.GetValue(o.GetOrdinal("deviceid")).ToString();
        string devicename = o.GetValue(o.GetOrdinal("devicename")).ToString();
        string devicetype = o.GetValue(o.GetOrdinal("devicetype")).ToString();
        string devicenum = o.GetValue(o.GetOrdinal("devicenum")).ToString();
        string hcheight = o.GetValue(o.GetOrdinal("hcheight")).ToString();
        string nodetype = o.GetValue(o.GetOrdinal("nodetype")).ToString();
        System.Xml.XmlNode xianluNode = linelistNode.SelectSingleNode("线路[属性[@columnname='overlineid' and @value='" + overlineid + "']]");
        System.Xml.XmlAttribute att ;    
        if (xianluNode == null)
        {
            System.Xml.XmlElement xianluNode1 = xmlDoc.CreateElement("线路");
            xianluNode = xianluNode1 as System.Xml.XmlNode;
            xianluNode1.SetAttribute("status", "=");
            xianluNode1.SetAttribute("title", "linename");
            AppendAttElement("tab_overline", "overlineid", "线路ID", overlineid, xmlDoc, xianluNode as System.Xml.XmlElement, false,true);
            AppendAttElement("tab_overline", "linename", "线路名称", linename,xmlDoc,xianluNode as System.Xml.XmlElement,true,false);
            linelistNode.AppendChild(xianluNode);
        }
        if (wireid == "" || wireid == null || finishtower== null || finishtower == "")
        {
            continue;
        }
        System.Xml.XmlNode wirenode1 = xianluNode.SelectSingleNode(".//导线[属性[@columnname='wireid' and @value='" + wireid + "']]");
        if (wirenode1 == null)
        {
            System.Xml.XmlElement wirenode = xmlDoc.CreateElement("导线");
            wirenode1 = wirenode as System.Xml.XmlNode;
            wirenode.SetAttribute("status", "=");
            wirenode.SetAttribute("title", "finishtowername");
            //不可更改
            AppendAttElement("tab_wire", "wireid", "导线ID", wireid, xmlDoc, wirenode, false,true);
            AppendAttElement("tab_wire", "belongline", "所属线路ID", overlineid, xmlDoc, wirenode, false,true);
            AppendAttElement("tab_wire", "starttower", "起点杆塔ID", starttower, xmlDoc, wirenode, false,true);
            AppendAttElement("tab_wire", "finishtower", "终点杆塔ID", finishtower, xmlDoc, wirenode, false,true);
            AppendAttElement("tab_wire", "finishtowername", "终点杆塔名称", finishtowername, xmlDoc, wirenode, true,false);
            //以上几个属性不可更改            
            //以下属性可根据需要随意更改
            AppendAttElement("tab_wire", "installtype", "埋设方式", installtype, xmlDoc, wirenode, true,false);
            AppendAttElement("tab_wire", "nodedist", "档距", nodedist, xmlDoc, wirenode, true,true);
            xianluNode.AppendChild(wirenode1);                                       
        }
        System.Xml.XmlNode towernode1 = towerlistNode.SelectSingleNode("杆塔[属性[@columnname='towerid' and @value='" + finishtower + "']]");
        if (towernode1 == null)
        {
            System.Xml.XmlElement towernode = xmlDoc.CreateElement("杆塔");
            towernode.SetAttribute("status", "=");
            //必须有，不可随意更改
            AppendAttElement("tab_tower", "towerid", "杆塔ID", finishtower, xmlDoc, towernode, false,true);
            AppendAttElement("tab_tower", "longitude", "经度", longitude, xmlDoc, towernode, false,true);            
            AppendAttElement("tab_tower", "latitude", "纬度", latitude, xmlDoc, towernode, false,true);            
            AppendAttElement("tab_tower", "elevation", "高程", elevation, xmlDoc, towernode, false,true);
            //以上几个属性不可更改    
            //以下属性皆可根据需要修改
            AppendAttElement("tab_tower", "hcheight", "杆塔高度", hcheight, xmlDoc, towernode, true,true);
            AppendAttElement("tab_tower", "nodetype", "杆塔类型", nodetype, xmlDoc, towernode, true,false);
            towerlistNode.AppendChild(towernode);
        }        
        if (deviceid != null && deviceid != "")
        {
            System.Xml.XmlElement shebeinode = xmlDoc.CreateElement("设备");
            shebeinode.SetAttribute("status", "=");
            shebeinode.SetAttribute("title", "devicename");
            //不可更改
            AppendAttElement("tab_device", "deviceid", "设备ID", deviceid, xmlDoc, shebeinode, false,true);
            AppendAttElement("tab_device", "devicename", "名称", devicename, xmlDoc, shebeinode, true,false);
            AppendAttElement("tab_device", "belongtower", "所属杆塔ID", finishtower, xmlDoc, shebeinode, false,true);
            AppendAttElement("tab_device", "belongline", "所属线路ID", overlineid, xmlDoc, shebeinode, false,true);
            //以上几个属性不可更改
            //以下属性可根据需要随意更改
            AppendAttElement("tab_device", "devicetype", "型号", devicetype, xmlDoc, shebeinode, true,false);
            AppendAttElement("tab_device", "devicenum", "数量", devicenum, xmlDoc, shebeinode, true,true);            
            wirenode1.AppendChild(shebeinode);
        }
    }
    Response.Output.Write(xmlDoc.InnerXml);    
 %>